package com.telewave.stompdemo.listeners;

import lombok.extern.slf4j.Slf4j;
import org.springframework.context.event.EventListener;
import org.springframework.messaging.simp.broker.BrokerAvailabilityEvent;
import org.springframework.messaging.support.GenericMessage;
import org.springframework.stereotype.Component;
import org.springframework.web.socket.messaging.*;

/**
 * TODO
 *
 * @author looveh
 * @since 2023/10/26 13:12:26
 **/
@Slf4j
@Component
public class WebSocketEventListener {

    @EventListener
    public void sessionConnectEventListener(SessionConnectEvent event) {
        // System.out.println("source: " + event.getSource());
        // System.out.println("message: " + event.getMessage());
        // System.out.println("timestamp: " + event.getTimestamp());
        // System.out.println("user: " + event.getUser());
        log.info("收到{}消息:{}", event.getClass().getSimpleName(),event);
    }

    @EventListener
    public void sessionConnectedEventListener(SessionConnectedEvent event) {
        log.info("收到{}消息:{}", event.getClass().getSimpleName(),event);
    }

    @EventListener
    public void sessionSubscribeEventListener(SessionSubscribeEvent event) {
        log.info("收到{}消息:{}", event.getClass().getSimpleName(),event);
    }

    @EventListener
    public void sessionUnsubscribeEventListener(SessionUnsubscribeEvent event) {
        log.info("收到{}消息:{}", event.getClass().getSimpleName(),event);
    }

    @EventListener
    public void sessionDisconnectEventListener(SessionDisconnectEvent event) {
        log.info("收到{}消息:{}", event.getClass().getSimpleName(),event);
    }

    @EventListener
    public void brokerAvailabilityEventListener(BrokerAvailabilityEvent event) {
        log.info("收到{}消息:{}", event.getClass().getSimpleName(),event);
    }
}
